package com.dylan.springcloud.comsumer.controller;

import com.dylan.springcloud.common.util.MapBuilder;
import com.dylan.springcloud.comsumer.model.User;
import com.dylan.springcloud.comsumer.service.UserFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Dylan on 2018/10/12.
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserFeignService userFeignService;

    @RequestMapping(value = "/add")
    public String addUser() {
        return userFeignService.addUser(1L, "安康", 29);
    }

    @RequestMapping(value = "/add2")
    public String addUser2() {
        Map<String, Object> user = MapBuilder.createBuilder(HashMap<String, Object>::new)
                .put("id", 2L)
                .put("name", "安2康")
                .put("age", 30)
                .build();
        return userFeignService.addUser(user);
    }

    @RequestMapping(value = "/add3")
    public String addUser3() {
        User user = new User();
        user.setId(3L);
        user.setName("安3康");
        user.setAge(31);
        return userFeignService.addUser(user);
    }

    @RequestMapping(value = "/update")
    public String updateUser() {
        User user = new User();
        user.setId(4L);
        user.setName("安4康");
        user.setAge(32);
        return userFeignService.updateUser(user);
    }
}
